package com.sts.sink.model;

import com.sts.sink.StsSink;
import com.sts.sink.impl.CsvSinkImpl;
import com.sts.source.StsSource;
import com.sts.task.StsTask;
import de.siegmar.fastcsv.writer.LineDelimiter;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class CsvSinkConfig extends BaseSinkConfig {

    private static final int DEFAULT_BUFFER_SIZE = 8192;

    private String filePath;
    private char fieldSeparator = ',';
    private char quoteCharacter = '"';
    private LineDelimiter lineDelimiter = LineDelimiter.CRLF;
    private int bufferSize = DEFAULT_BUFFER_SIZE;

    public CsvSinkConfig(String filePath) {
        this.filePath = filePath;
    }

    public CsvSinkConfig(String filePath, char fieldSeparator, char quoteCharacter, LineDelimiter lineDelimiter, int bufferSize) {
        this.filePath = filePath;
        this.fieldSeparator = fieldSeparator;
        this.quoteCharacter = quoteCharacter;
        this.lineDelimiter = lineDelimiter;
        this.bufferSize = Math.min(bufferSize, DEFAULT_BUFFER_SIZE);
    }

    public void setBufferSize(int bufferSize) {
        this.bufferSize = Math.min(bufferSize, DEFAULT_BUFFER_SIZE);
    }

    @Override
    public StsSink buildImpl(StsSource stsSource, StsTask stsTask) {
        return new CsvSinkImpl(stsSource, this, stsTask);
    }
}
